package com.chaofan.sell.utils;

import com.chaofan.sell.enums.Code;

/**
 * @author Fairy
 * @date 2021/9/25
 */
public class EnumUtil {

    /**
     * 获取枚举
     *
     * @param code      枚举数值
     * @param enumClass 枚举类
     * @param <T>       枚举类
     * @return 枚举信息
     */
    public static <T extends Code> T getByCode(Integer code, Class<T> enumClass) {
        for (var each : enumClass.getEnumConstants()) {
            if (code.equals(each.getCode())) {
                return each;
            }
        }
        return null;
    }
}
